package likou;

import java.util.Stack;

/**
 * @description: 用栈实现队列
 * @title: MyQueue
 * @author: zp
 * @date: 2022/2/23 19:24
 */
public class MyQueue {
    private Stack<Integer> stack;
    private Stack<Integer> lastStack;
    public MyQueue() {
        stack = new Stack<>();
        lastStack = new Stack<>();
    }

    public void push(int x) {
        if(stack.empty()){
            stack.push(x);
        }else {
            while (!stack.empty()){
                lastStack.push(stack.pop());
            }
            lastStack.push(x);
            while (!lastStack.empty()){
                stack.push(lastStack.pop());
            }
        }
    }

    public int pop() {
        return stack.pop();
    }

    public int peek() {
        return stack.peek();
    }

    public boolean empty() {
        return stack.empty();
    }
}
